#include "std_unique_ptr.h"
#include "std_shared_ptr.h"

int std_unique_ptr() {
    //! 1. delete掉了拷贝和赋值构造
    std::unique_ptr<int> p1(new int(1));
    // std::unique_ptr<int> p2(p1);              //! Complie Error:  copy construct delete
    // std::unique_ptr<int> p2 = p1;             //! Complie Error:  asign construct delete

    // std::unique_ptr<int> p2(std::move(p1));   // OK
    // std::unique_ptr<int> p2 = std::move(p1);  // OK

    //! 2. unique_ptr可以指向数组， shared_ptr不能
    std::unique_ptr<int[]> p3(new int[10]);
    // std::shared_ptr<int[]> p3(new int[10]);    //! Complie Error

    //! 3. unique_ptr指针删除器时要指定删除器类型
    std::shared_ptr<int> p4(new int(1),  [](int* p) { delete p;});                    // OK
    // std::unique_ptr<int> p4(new int(1),  [](int* p) { delete p;});                 //! Compile Error
    std::unique_ptr<int, void(*)(int*)> p5(new int(1),  [](int* p) { delete p;});     // OK
    // std::unique_ptr<int, void(*)(int*)> p4(new int(1),  [&](int* p) { delete p;});  //! Compile Error
    std::unique_ptr<int, std::function<void(int*)> > p6(new int(1),  [&](int* p) { delete p;});  // OK

    std::unique_ptr<int, shared_ptr_struct_deleter<int>> p7(new int(1));    

    return 0;
}